import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {},
		userData:{},
		token: null,
		loginProvider: "",
		openId :null,
		order:false,
		apiUrl:'https://www.quyidian.com.cn/',
		tabbarid:'',
		pid:'',
		lngs1:'',
		lats1:''
	},
	mutations: {
		//缓存用户Token信息
		setToken(state, token) {
			state.token = token;
			uni.setStorage({
				key: 'token',
				data: token
			})
		},
		setLng(state, lng) {
			state.lngs1 = lng;
		},
		setlat(state, lat) {
			state.lats1 = lat;
		},
		settabbar(state, id) {
			state.tabbarid = id;
			uni.setStorage({
				key: 'tabbarid',
				data: id
			})
		},
		setorder(state, order) {
			state.order = order;
		},
		setpid(state, id) {
			state.pid = id;
		},
		//缓存用户openId
		setOpenid(state, openId) {
			state.openId = openId;
			uni.setStorage({
				key: 'openId',
				data: openId
			})
		},
		
		
		//登陆
		login(state, userInfo) {
			state.hasLogin = true;
			state.userInfo = userInfo;
			uni.setStorage({
				key: 'userInfo',
				data: userInfo
			})
			uni.setStorage({
				key: 'hasLogin',
				data: true
			})
		},
		
		logout(state) {
			state.hasLogin = false;
			uni.removeStorage({
				key: 'userInfo'
			})
			uni.removeStorage({
				key: 'openId'
			})
			uni.removeStorage({
				key: 'hasLogin'
			})
		}
	},
	actions: {

	}
})

export default store